package cn.com.nr.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;

import cn.com.common.result.DataResult;
import cn.com.nr.entity.NrCalculateEntity;
import cn.com.nr.service.NrCalculateService;
import cn.com.util.TsBqUtils;

/**
 * 
 *
 * @author shaochangyang
 * @email l2l84o7o5@live.com
 * @date 2025-04-06 18:18:01
 */
@Controller
@RequestMapping("/nr/calculate")
public class NrCalculateController {
	@Autowired
	private NrCalculateService nrCalculateService;

	@ApiOperation(value = "更新")
	@PutMapping("/update")
	@ResponseBody
	public DataResult update(@RequestBody NrCalculateEntity nrCalculate) {
		String id = nrCalculate.getId();
		if (TsBqUtils.isNull(id)) {
			return DataResult.fail("入参ID不能为空");
		}

		nrCalculateService.updateById(nrCalculate);
		return DataResult.success();
	}

	@SuppressWarnings("unchecked")
	@ApiOperation(value = "查询分页数据")
	@PostMapping("/list")
	@ResponseBody
	public DataResult list(@RequestBody NrCalculateEntity nrCalculate) {
		String id = nrCalculate.getId();
		if (TsBqUtils.isNull(id)) {
			return DataResult.fail("入参ID不能为空");
		}

		@SuppressWarnings("rawtypes")
		Page page = new Page(nrCalculate.getPage(), nrCalculate.getLimit());
		LambdaQueryWrapper<NrCalculateEntity> queryWrapper = Wrappers.lambdaQuery();
		// 查询条件示例
		queryWrapper.eq(NrCalculateEntity::getId, nrCalculate.getId());
		IPage<NrCalculateEntity> iPage = nrCalculateService.page(page, queryWrapper);
		return DataResult.success(iPage);
	}

}
